package com.hzit.handler;

import com.hzit.exception.NotPermissionException;
import com.hzit.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice

@Slf4j
public class HzitGlobalExceptionHandler {

	@ExceptionHandler(NotPermissionException.class)
	public R handlerNotPermissionException(NotPermissionException e){
		log.error("未授权,{}",e.getMessage());
		return R.fail(HttpStatus.FORBIDDEN.value(),"没有权限，请联系管理员");
	}
	@ExceptionHandler(RuntimeException.class)
	public R handlerRuntimeExceptionException(RuntimeException e){
		log.error("运行异常,{}",e.getMessage());
		return R.fail(HttpStatus.FORBIDDEN.value(),"运行出错");
	}
	@ExceptionHandler(Exception.class)
	public R handlerExceptionException(Exception e){
		log.error("未知异常,{}",e.getMessage());
		return R.fail(HttpStatus.FORBIDDEN.value(),"未知异常");
	}
}
